<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: shop_content.php 448 2014-01-19 12:05:00Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 448 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-19 12:05:00 +0000 (Sun, 19 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */
define('GLOBAL_COLUMN_LEFT', '0');
require ('includes/application_top.php');

$smarty = new Smarty();

require (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');
require_once (DIR_FS_INC.'inc.validate_email.php');
require_once (DIR_FS_INC.'inc.add_js_plugin.php');

if(GROUP_CHECK == 'true')
	$group_check = " AND group_ids LIKE '%c_".$_SESSION['customers_status']['customers_status_id']."_group%'";

$CACHE_CONTENT_ID = '';

$shop_content_data = $db->db_query("SELECT
										content_id,
										content_title,
										content_heading,
										content_text,
										content_file,
										content_show_pdf,
										content_show_print,
										content_show_back
									FROM
										".TABLE_CONTENT_MANAGER."
									WHERE
										content_group = '".(int)$_GET['coID']."' ".$group_check."
									AND
										languages_id = '".(int)$_SESSION['languages_id']."'", true);
$breadcrumb->add($shop_content_data->fields['content_title'], href_link(FILENAME_CONTENT,'coID='.(int) $_GET['coID']));

if ($_GET['coID'] != 7)
	require (DIR_WS_INCLUDES.'header.php');
	
if ($_GET['coID'] == 7 && $_GET['action'] == 'success')
	require (DIR_WS_INCLUDES.'header.php');

$smarty->assign('CONTENT_HEADING', $shop_content_data->fields['content_heading']);

if ($_GET['coID'] == 7) {
  if (file_exists(DIR_FS_DOCUMENT_ROOT.'media'.DS.'content'.DS.'contact_us.php'))
    include(DIR_FS_DOCUMENT_ROOT.'media'.DS.'content'.DS.'contact_us.php');

  else {
  	$error = false;
  	if(isset ($_POST['action']) && ($_POST['action'] == 'send')) {
  		if(SHOW_DSG_ON_CONTACT_FORM == 'true' && $_POST['datensg'] != 'yes') {
  			$error = true;
  			$message_stack->add(ERROR_CDATENSG, 'error');
  		}

  		if((SHOW_CAPTCHA_ON_CONTACT_FORM == 'true') && (empty($_POST['security_code']) || ($_POST['security_code'] != $_SESSION['security_code_shop_content']))) {
  			$error = true;
  			$message_stack->add(TEXT_CAPTCHA_ERROR, 'error');
  		}

  		if(!validate_email(trim($_POST['email']))) {
  			$error = true;
  			$message_stack->add(ERROR_MAIL, 'error');
  		}

  		if(!$error) {
  			$smarty->assign('MAIL_TEXT', nl2br($_POST['message_body']));
  			$smarty->assign('ASK_NAME', $_POST['name']);

  			$smarty->caching = false;
  			require_once(DIR_FS_INC.'inc.get_mail_body.php');
  			$html_mail .= $smarty->fetch('html:contact');
  			$html_mail .= $signatur_html;
  			$txt_mail .= $smarty->fetch('txt:contact');
  			$txt_mail .= $signatur_text;
  			require_once(DIR_FS_INC.'inc.get_mail_data.php');
  			$mail_data = get_mail_data('contact');

  			$contact_subject = str_replace('{$date}', strftime(DATE_FORMAT_LONG), $mail_data['EMAIL_SUBJECT']);
  			$contact_subject = str_replace('{$shop_besitzer}', STORE_OWNER, $contact_subject);
  			$contact_subject = str_replace('{$shop_name}', STORE_NAME, $contact_subject);

  			php_mail($_POST['email'],
  						$_POST['name'],
  						$mail_data['EMAIL_ADDRESS'],
  						$mail_data['EMAIL_ADDRESS_NAME'],
  						$mail_data['EMAIL_FORWARD'],
  						$_POST['email'],
  						$_POST['name'],
  						'',
  						'',
  						$contact_subject,
  						$html_mail,
  						$txt_mail);

  			unset($_SESSION['security_code_shop_content']);
  			unset($_SESSION['captcha']);
  			redirect(href_link(FILENAME_CONTENT, 'action=success&coID='.(int)$_GET['coID']));
  		}
  		if($message_stack->size > 0)
  			$get[] = 'msg=1';
  	}

  	$smarty->assign('CONTACT_HEADING', $shop_content_data->fields['content_title']);
  	if (isset ($_GET['action']) && ($_GET['action'] == 'success')) {
  		$smarty->assign('success', '1');
  		$smarty->assign('BUTTON_CONTINUE', '<a href="'.href_link(FILENAME_DEFAULT).'">'.image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE).'</a>');

  	} else {
  		if($shop_content_data->fields['content_file'] != '') {
  			ob_start();
  			if (strpos($shop_content_data->fields['content_file'], '.txt'))
  				echo '<pre>';
  			include (DIR_FS_CATALOG.'media/content/'.$shop_content_data->fields['content_file']);
  			if (strpos($shop_content_data->fields['content_file'], '.txt'))
  				echo '</pre>';
  			$contact_content = ob_get_contents();
  			ob_end_clean();
  		} else
  			$contact_content = $shop_content_data->fields['content_text'];

  		require (DIR_WS_INCLUDES.'header.php');
  		$smarty->assign('CONTACT_CONTENT', $contact_content);
  		$smarty->assign('FORM_ACTION', draw_form('contact_us', href_link(FILENAME_CONTENT, 'coID='.(int)$_GET['coID'])).draw_hidden_field('action', 'send'));

  	function get_customer_mail($customer_id) {
  		global $db;
  		$customer_info = $db->db_query("SELECT customers_email_address FROM ".TABLE_CUSTOMERS." WHERE customers_id = '".$customer_id."'");
  		return $customer_info->fields['customers_email_address'];
  	}

      if(isset($_SESSION['customer_id'])) {
  		$name = $_SESSION['customer_first_name'].' '.$_SESSION['customer_last_name'];
  		$smarty->assign('INPUT_NAME', draw_input_field('name', $name));
  		$smarty->assign('INPUT_EMAIL', draw_input_field('email', get_customer_mail((int)($_SESSION['customer_id']))));

      } else {
  		$name = ($error ? $_POST['name'] : $first_name);
  		$smarty->assign('INPUT_NAME', draw_input_field('name', $name));
  		$smarty->assign('INPUT_EMAIL', draw_input_field('email', ($error ? $_POST['email'] : $email_address)));
      }
  		$smarty->assign('INPUT_TEXT', draw_textarea_field('message_body', 'soft', 50, 15, $_POST['message_body']));
  		$smarty->assign('BUTTON_SUBMIT', image_submit('button_continue.gif', IMAGE_BUTTON_SEND));

  		if(SHOW_CAPTCHA_ON_CONTACT_FORM == 'true') {
  			$captcha_site = '_shop_content';
  			include('captcha.php');
  			$smarty->assign('VVIMG', '<img width="200" height="70" src="captcha.php?show=true&name=shop_content" alt="Captcha" id="captcha_image" /> ');
  			$smarty->assign('INPUT_CAPTCHA', draw_input_field('security_code', '', 'size="6" maxlength="6" style="width:25px; text-align:center" id="security_code"', 'text', false));
  		}

  		if(SHOW_DSG_ON_CONTACT_FORM == 'true') {
  			$dsg_text = (SITE_OVERLAYS == 'true' ? sprintf(INFO_DSG_OVERLAY, href_link(FILENAME_POPUP_CONTENT, 'coID=2&iframe=true')) : sprintf(INFO_DSG_POPUP, href_link(FILENAME_CONTENT, 'coID=2')));
  			$smarty->assign('DATENSG', draw_checkbox_field('datensg', 'yes').' '.$dsg_text);
  		}
  		$smarty->assign('FORM_END', '</form>');
  	}

  	$smarty->assign('language', $_SESSION['language']);

  	$smarty->caching = false;
  	$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/contact_us.html');
  } // kein file in /media gefunden ..
} else {

	if($shop_content_data->fields['content_show_pdf'] == 1)
		$smarty->assign('PDF_LINK','<a href="'.href_link(FILENAME_PRINT_PDF,'content='.$_GET['coID']).'">'.image('images/button_pdf.gif',IMAGE_BUTTON_PRINT_PDF).'</a>');

	if($shop_content_data->fields['content_show_print'] == 1)
		$smarty->assign('PRINT_LINK','<a href="javascript:popupWindowShipping(\''.href_link(FILENAME_POPUP_CONTENT,'coID='.$_GET['coID']).'\')">'.image('images/button_print.gif',IMAGE_BUTTON_PRINT_CONTENT).'</a>');

	if($shop_content_data->fields['content_show_back'] == 1)
		$smarty->assign('BUTTON_CONTINUE', '<a class="mt10" href="javascript:history.back(1)">'.image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>');

	if ($shop_content_data->fields['content_file'] != '') {
		ob_start();
		if (strpos($shop_content_data->fields['content_file'], '.txt'))
			echo '<pre>';
		include (DIR_FS_CATALOG.'media/content/'.$shop_content_data->fields['content_file']);
		if (strpos($shop_content_data->fields['content_file'], '.txt'))
			echo '</pre>';
		if (strpos($shop_content_data->fields['content_file'], '.htm')) {
    	$content_body = utf8_encode(ob_get_contents());
    }
    else
  		$smarty->assign('file', ob_get_contents());
		ob_end_clean();

	} else
		$content_body = $shop_content_data->fields['content_text'];

  echo $smarty->getTemplateVars('CONTENT_HEADER');
/*echo '----------------

-----------
';
  echo $smarty->getTemplateVars('file'); die(); */
	$smarty->assign('CONTENT_BODY', $content_body);
  $smarty->assign('language', $_SESSION['language']);

	// set cache ID
	 if (!CacheCheck()) {
		$smarty->caching = false;
		$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/content.html');
	} else {
		$smarty->caching = true;
		$smarty->cache_lifetime = CACHE_LIFETIME;
		$smarty->cache_modified_check = CACHE_CHECK;
		$cache_id = $_SESSION['language'].'_'.$_SESSION['customers_status']['customers_status_id'].'_'.$shop_content_data->fields['content_id'].'id'.$CACHE_CONTENT_ID;
		$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/content.html', $cache_id);
	}
}
//die($main_content);
$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
$smarty->caching = false;
$smarty->loadFilter('output', 'note');
$smarty->loadFilter('output','trimwhitespace');
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include ('includes/application_bottom.php');